// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import router from './router';

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

import encryptionService from './utils/encryptionService';
// 将加密服务注册为Vue的原型方法，使其在所有组件中可用
Vue.prototype.$encryption = encryptionService;

import { axios, api } from './Axios';
Vue.prototype.$axios = axios;
Vue.prototype.$api = api;
import VueAxios from 'vue-axios';
Vue.use(VueAxios, axios);

import _ from 'lodash';
Vue.prototype._ = _;

// 通过script引入 dist/server_config.js 作为配置文件
// 开发时 window.server_config 只能返回 undefined
// 打包上线后 window.server_config 就可以返回配置对象
// 然后通过下面 mergeConfig 方法将两者合并返回可用的配置对象并存入原型链就可以全局使用了
import { mergeConfig } from './mergeConfig.js';
let serverConfig = null;
if (_.has(window, 'server_config')) {
  serverConfig = window.server_config.getServerConfig();
}
let $config = mergeConfig(serverConfig);

Vue.prototype.$config = $config;

import Mockjs from 'mockjs';
Vue.prototype.$mock = Mockjs;

import Moment from 'moment';
import 'moment/locale/zh-cn';
Vue.prototype.$moment = Moment;

import '@/assets/reset.css';
Vue.config.productionTip = false;

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
});
